#include <iostream>
#include "looper.h"

using namespace looper;

static uint64_t prvGetUpMillis()
{
	timespec now;
	clock_gettime(CLOCK_MONOTONIC, &now);
	return now.tv_sec*1000LL + now.tv_nsec/1000000LL;
}

class Runnable : public IRunnable
{
public:
	void run() override
	{		
		std::cout << "hello world " << prvGetUpMillis() << std::endl;
	}
};


class MyHandler : public Handler
{
public:
	MyHandler() : Handler(&mLooper) {}
	
private:
	Looper mLooper;
};

int main()
{	
	MyHandler h;
	RunnableSP r(new Runnable);
	
	std::cout << "hello now = " << prvGetUpMillis() << std::endl;
	
	h.post(r);
	h.postDelayed(r, 500);
	
	h.post(r);
	h.postDelayed(r, 1000);
	
	h.post(r);
	h.postDelayed(r, 1200);
	
	h.post(r);
	h.postDelayed(r, 2000);	
	
	h.postDelayed(r, 3000);	
	
	std::this_thread::sleep_for(std::chrono::milliseconds(2200));
}
